(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=scorpion7552
Title=AllGame
Description=import games - Default platform & Normal/Batch mode: see Comments tab
Site=www.allgame.com
Language=EN
Version=2.0
Requires=3.5.0
Comments=default platform: after selecting option 1 or 2 for platform, don't forget to select option 0 the next time you run this script||Batch mode: you must have a database already created with this script (I use the url stored)|Don't forget to save your database before executing the batch mode and select a reasonable number of games at a time|At the end of each round, look at file C:\amc_AllGame_batchlog.txt for informations and errors (this file is re-create each time you run this script)
License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
GetInfo=1
[Options]
Platform=0|0|0=use current setting|1=choose default platform|2=reset default platform
Mode=0|0|0=normal mode|1=batch mode (url)
***************************************************)
// needs the following units
// StringUtils1.pas, StringUtils7552.pas
program AllGame;
uses
StringUtils7552;
const
AllGameUrl = 'http://www.allgame.com'; // base url
batchlogfic = 'c:\amc_AllGame_batchlog.txt'; // log for batch mode
platformopt = 'Platform'; // name of platform Static option
// debug mode
debug = False; // debug mode on/off
debugrep = 'd:\temp\'; // directory where to save files
var
GameName, platformc, firstcall, abort, msgano: String;
BatchMode, dfltPlatform: Integer;
batchlog, confbatch, memo: TstringList;
gameok: boolean;
//------------------------------------------------------------------------------
// get platform id (normal mode only)
// on output, platformc = name of selected platform
//------------------------------------------------------------------------------
procedure GetPlatform;
var
Page, Line, Table, urlplatform: string;
i: integer;
begin
msgano := 'Enter platform name';
if dfltPlatform = 1 then // change default platform
begin
platformc := GetStatic(platformopt); // get old default or ''
msgano := 'Select a (new) default platform';
end;
repeat
// enter platform name; leave script if nothing entered
if not Input('AllGame.com Import', msgano, platformc) or (platformc = '') then exit;
// look if there is something matching platformc
Page := PostPage(AllGameUrl+'/cg/agg.dll', 'SRCH='+platformc+'&P=agg&TYPE=5');
if debug then
DumpPage(debugrep+'SelPlatformAllGame.txt', Page); // debug
if Pos('Game Platforms Matching', Page) = 0 then
begin
ShowError('Error while reading platform page');
exit; // leave script if big error
end;
// selection table
Table := TextBetween(Page, '
');
if Table = '' then
begin
msgano := 'No platform found for "'+platformc+'"'; // iterate
platformc := '';
end else
begin
// extract matching platform names (displayed on a single page)
memo := TStringList.Create;
memo.Text := StringReplace(Table, '', crlf); // separate lines (keep other crlf)
PickTreeClear; // clear list
PickTreeAdd('Select platform', '');
urlplatform := 'HREF=/cg/agg.dll'; // url to search
for i := 0 to memo.Count -1 do // list of games
begin
Line := memo.GetString(i); // extract current line
if GetUrl(Line, urlplatform, AllGameUrl) = '' then continue; // no url: header or empty line
Line := TextBefore(Line, '', '>'); // platform name
PickTreeAdd(Line, Line);
end; {for i}
memo.Free;
if not PickTreeExec(platformc) then
msgano := 'No platform selected'; // iterate if no platform selected
end;
until (platformc <> '');
if dfltPlatform = 1 then
begin
SetStatic(platformopt, platformc); // save new default platform
ShowInformation('Default platform "'+platformc+'" have been saved'+crlf+'Next time, don''t forget to set the option back to 0');
end;
end;
//------------------------------------------------------------------------------
// list of games running on platformc
// GameName = name of game
//------------------------------------------------------------------------------
procedure GetList;
var
Address, Table, Line, Value, Page, urlgame, name, genre: String;
found: boolean;
i: integer;
begin
PickTreeClear; // clear list
found := False;
PickTreeAdd('List of games (platform='+platformc+')', '');
Page := PostPage(AllGameUrl+'/cg/agg.dll', 'SRCH='+UrlEncode(GameName)+'&P=agg&TYPE=1');
if debug then
DumpPage(debugrep+'choiceAllGame.txt', Page); // debug
if Pos('Games with Titles Matching', Page) = 0 then
begin
LogMessage('Error while reading selection page');
exit;
end;
if Pos('No matches found', Page) > 0 then
begin
LogMessage('No matches found for "'+GameName+'"');
exit;
end;
// selection table
// note: the games are displayed on one page and are sorted by relevance
Table := TextBetween(Page, '');
// strange coding
// normally, a table has the following structure
// = start of line
// text | = one cell
// ................ = other cells
//
= end of line
// but, I don't know why they omit the in this table
// so, I have to separate lines with ''); // usefull infos
Line := StringReplace(Line, '', sepchar1); // separate fields with
Line := FormatText(Line); // remove extra tags
name := Trim(TextBefore(Line, sepchar1, '')); // name of the game
Line := RemainingText;
genre := Trim(TextBefore(Line, sepchar1, '')); // genre
Line := RemainingText;
Line := TextBefore(Line, sepchar1, '');
Line := RemainingText; // skip style
Value := Trim(TextBefore(Line, sepchar1, '')); // Platform
// 'IBM PC Compatible' = PC, PC DOS Win95, etc...
if Left(Value, 2) = 'PC' then Value := 'IBM PC Compatible';
if Value = platformc then // current game runs on selected platform
begin
PickTreeAdd(name+' ('+genre+')', Address);
found := True;
end;
end; {for i}
memo.Free;
if not found then
begin
LogMessage('No game found for "'+GameName+'" running on "'+platformc+'"');
exit;
end;
PickTreeSort; // sort the list
if PickTreeExec(Address) then
AnalyzeGamePage(Address) // game page
else
LogMessage('No game selected');
end;
//------------------------------------------------------------------------------
// ANALYZE GAME PAGE
//------------------------------------------------------------------------------
procedure AnalyzeGamePage(Address: string);
var
Page, Line, Table, Value, Value2, screenshot, cover: String;
i: Integer;
begin
Page := GetPage(Address);
if debug then
DumpPage(debugrep+'gameAllGame.txt', Page); // debug
if Pos('Release', Page) = 0 then
Begin
LogMessage('Error while reading game page');
exit;
end;
SetField(fieldURL, Address);
gameok := True;
//*** title (original only)
Table := TextBetween(Page, '');
Table := FormatText(Table);
if Table <> '' then
SetField(fieldOriginalTitle, Table);
// rating (
', '');
Table := StringReplace(Table, crlf, ''); // must remove crlf
memo := TStringList.Create;
memo.Text := StringReplace(Table, '
', crlf); // separate lines
if memo.Text <> '' then
begin
Value := memo.GetString(0); // platform
SetField(fieldCountry, FormatText(Value));
Value := memo.GetString(1); // genre
SetField(fieldCategory, FormatText(Value));
end;
memo.Free;
// get 1st screenshot if any
Table := TextBetween(Page, '');
if Table <> '' then
screenshot := GetUrl(Table, '', '');
//*** release date (year only) ('month year' 'month day, year' or 'year')
Table := TextAfter(Page, ''); // more than one table
Value := FormatText(TextBetween(Table,'Release', ''));
i := LastPos(' ', Value); // extract year only
if i > 0 then Value := Copy(Value, i+1, length(Value));
SetField(fieldYear, Value);
// developper (= director)
Value := TextBetween(Table,'Developer', '');
SetField(fieldDirector, FormatText(Value));
// publisher (= producer)
Value := TextBetween(Table,'Publisher', '');
SetField(fieldProducer, FormatText(Value));
// various infos (= comments) controls, hardware supported, etc...
Value2 := '';
Value2 := Value2+ExtrInfo(Table,'Controls');
Value2 := Value2+ExtrInfo(Table,'Warnings');
Value2 := Value2+ExtrInfo(Table,'Flags');
Value2 := Value2+ExtrInfo(Table,'Hardware Supported');
Value2 := Value2+ExtrInfo(Table,'Supports');
Value2 := Value2+ExtrInfo(Table,'Included in Package');
Value2 := Value2+ExtrInfo(Table,'Similar Games');
SetField(fieldComments, FormatText(Value2));
//*** description and image
Line := '';
Value := TextBetween(Page, Line, '
'); // 1st (or only) description
Table := RemainingText; // is there another description ?
if Value <> '' then
begin
cover := TextBetween(Value, '
'));
if Value2 <> '' then // another description
Value := Value+crlf+Value2;
end;
SetField(fieldDescription, Value);
if cover = '' then cover := screenshot; // no cover: get 1st screenshot if any
if (cover <> '') and CanSetPicture then
GetPicture(cover);
end;
//------------------------------------------------------------------------------
// extract 'various infos'
//------------------------------------------------------------------------------
function ExtrInfo(str1, str2: string) :string;
begin
str1 := FormatText(TextBetween(str1, str2, ''));
if str1 <> '' then str1 := crlf+str2+': '+str1;
result := str1;
end;
//------------------------------------------------------------------------------
// set msgano (normal mode) or add to log (batch mode)
//------------------------------------------------------------------------------
procedure LogMessage(m: string);
begin
if BatchMode > 0 then
AddToLog('item '+GetField(fieldNumber)+': '+m)
else
msgano := m;
end;
//------------------------------------------------------------------------------
// add a message in the batch log and save to disk
// (because I don't know when it's finished...)
//------------------------------------------------------------------------------
procedure AddToLog(m: string);
begin
batchlog.Add(m);
batchlog.SaveToFile(batchlogfic);
end;
//------------------------------------------------------------------------------
// process batch mode
//------------------------------------------------------------------------------
procedure AllGameBatch;
begin
GameName := GetField(fieldUrl); // if no url or another site then ignore
if (GameName <> '') and (Pos(AllGameUrl, GameName) > 0) then
AnalyzeGamePage(GameName)
else
LogMessage('ignored url="'+GameName+'"');
end;
//------------------------------------------------------------------------------
// process normal mode
//------------------------------------------------------------------------------
procedure AllGameNorm;
begin
platformc := '';
case dfltPlatform of
0: platformc := GetStatic(platformopt); // current = default platform or ''
1: platformc := ''; // choose (new) default
2: // reset default platform
begin
platformc := '';
SetStatic(platformopt, ' ');
end;
end;
gameok := False;
if platformc = '' then
GetPlatform; // if no default, select platform
if platformc <> '' then
begin
GameName := GetField(fieldOriginalTitle); // then game name
msgano := 'Enter game name for platform "'+platformc+'"';
repeat
if not Input('AllGame.com Import', msgano, GameName) or (GameName = '') then exit;
GetList;
until gameok;
end;
end;
//------------------------------------------------------------------------------
// start here
//------------------------------------------------------------------------------
begin
if abort = 'o' then exit; // batch mode aborted
if firstcall <> 'done' then
begin // 1st call: init parameters
firstcall := 'done';
if not CheckVersion(3,5,0) then
begin
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
abort := 'o';
exit;
end;
// get user's parms (used more than once)
dfltPlatform := GetOption(platformopt);
BatchMode := GetOption('Mode');
//
if BatchMode > 0 then // batch mode: confirm the choice
begin
batchlog := TStringList.Create; // init batch log
batchlog.Add('starting batch mode');
batchlog.Add(StringOfChar('*',80));
batchlog.SaveToFile(batchlogfic);
// confirmation message
confbatch := TStringList.Create;
confbatch.Add('You have selected the batch mode:');
confbatch.Add('Have you saved your database?');
confbatch.Add('');
confbatch.Add('At the end of treatement:');
confbatch.Add('- look at the file '+batchlogfic+' for errors/infos');
confbatch.Add('- the games found will be checked, the others not (for the selection)');
confbatch.Add(' (see: Tools/Preferences/Movie list/checkboxes)');
confbatch.Add('');
confbatch.Add('confirm your choice');
if not ShowWarning(confbatch.Text) then
begin
AddToLog('batch mode aborted'); // batch mode not confirmed = abort
abort := 'o';
exit;
end;
end;
end;
// let's go
if BatchMode = 0 then
AllGameNorm
else
AllGameBatch;
end.